import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TDelegate } from "../../../Message/Db/Tables/TDelegate";
import { EDelegateType } from "../../../Message/Game/EDelegateType";
import { Global } from "../../../com/gengine/global/Global";
import { CopyCodeRule } from "../rules/CopyCodeRule";
import { CopyConfig } from "./CopyConfig";
import { CopyUtil } from "../view/copy/CopyUtil";
import { Language } from "../../../extend/language/Language";
import { ItemData } from "./info/ItemData";
import { ItemsUtil } from "../view/shortcuts/item/ItemsUtil";
import { EDelegateKind } from "../../../Message/Game/EDelegateKind";
type int = number;
//class DelegateConfig
    
    export  class DelegateConfig
    {
        constructor()
        {
            
            this._taskDelegateMap = new Map<any, any> /* flash.utils.Dictionary */();
            this._copyDelegateMap = new Map<any, any> /* flash.utils.Dictionary */();
            if (DelegateConfig._instance != null) 
            {
                throw new Error(" DelegateConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_delegate.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TDelegate();
                loc1.code = loc2.code;
                loc1.coin = loc2.coin;
                loc1.expirenceCoin = loc2.expirenceCoin;
                loc1.expirenceGold = loc2.expirenceGold;
                loc1.gold = loc2.gold;
                loc1.reward = loc2.reward;
                loc1.timeCoin = loc2.timeCoin;
                loc1.timeGold = loc2.timeGold;
                loc1.type = loc2.type;
                loc1.warfareCoin = loc2.warfareCoin;
                loc1.warfareGold = loc2.warfareGold;
                loc1.icon = loc2.icon;
                loc1.passTimes = loc2.passTimes;
                if (loc1.type == EDelegateType._EDelegateTypeCopy) 
                {
                    this._copyDelegateMap[loc1.code] = loc1;
                    if (Global.isDebugModle && (loc1.code == CopyCodeRule.Copy60Defence || loc1.code == CopyCodeRule.CopyCrossDefenceHard)) 
                    {
                        loc1.passTimes = 1;
                    }
                    continue;
                }
                if (loc1.type != EDelegateType._EDelegateTypeTask) 
                {
                    continue;
                }
                this._taskDelegateMap[loc1.code] = loc1;
            }
            return;
        }

        public DelegateConfig.get copyMap(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._copyDelegateMap;
        }

        public getDelegateInfoByCode(arg1: int): TDelegate
        {
            return this._copyDelegateMap[arg1];
        }

        public getInfoByCopyCode(arg1: int): TDelegate
        {
            return this._copyDelegateMap[arg1];
        }

        public getRewardDesc(arg1: TDelegate): string
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            if (arg1) 
            {
                if (arg1.type == EDelegateType._EDelegateTypeCopy) 
                {
                    loc1 = CopyConfig.instance.getInfoByCode(arg1.code);
                    loc2 = CopyUtil.getCopyRewards(loc1);
                    if (loc2.length > 0) 
                    {
                        loc3 = loc2.length > 1 ? Language.getString(69617) : "";
                        loc4 = loc2[0] as ItemData;
                        return ItemsUtil.getItemName(loc4) + loc3;
                    }
                }
            }
            return "";
        }

        public getTypeName(arg1: int): string
        {
            if (arg1 == EDelegateKind._EDelegateKindCoin) 
            {
                return Language.getString(69615);
            }
            if (arg1 == EDelegateKind._EDelegateKindGold) 
            {
                return Language.getString(69616);
            }
            if (arg1 == EDelegateKind._EDelegateKindFree) 
            {
                return Language.getString(69661);
            }
            return "";
        }

        public getDelegateName(arg1: TDelegate): string
        {
            var loc1=null;
            if (!arg1) 
            {
                return "";
            }
            var loc2="";
            if (arg1.type != EDelegateType._EDelegateTypeCopy) 
            {
                if (arg1.type != EDelegateType._EDelegateTypeTask) 
                {
                };
            }
            else 
            {
                loc1 = CopyConfig.instance.getInfoByCode(arg1.code);
                loc2 = loc1 ? loc1.name : "";
            }
            return loc2;
        }

        public getTime(arg1: int, arg2: TDelegate): int
        {
            var loc1=0;
            if (arg2) 
            {
                if (arg1 != EDelegateKind._EDelegateKindCoin) 
                {
                    if (arg1 == EDelegateKind._EDelegateKindGold) 
                    {
                        loc1 = arg2.timeGold;
                    }
                }
                else 
                {
                    loc1 = arg2.timeCoin;
                }
            }
            return loc1;
        }

        public getDelegateExp(arg1: int, arg2: TDelegate): int
        {
            if (arg1 == EDelegateKind._EDelegateKindCoin) 
            {
                return arg2.expirenceCoin;
            }
            if (arg1 == EDelegateKind._EDelegateKindGold || arg1 == EDelegateKind._EDelegateKindFree) 
            {
                return arg2.expirenceGold;
            }
            return 0;
        }

        public getCost(arg1: int, arg2: TDelegate): int
        {
            if (arg1 == EDelegateKind._EDelegateKindCoin) 
            {
                return arg2.coin;
            }
            if (arg1 == EDelegateKind._EDelegateKindGold) 
            {
                return arg2.gold;
            }
            return 0;
        }

        public getFirstCopyCode(): int
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._copyDelegateMap;
            for(loc1 of loc3) 
            {
                return loc1.code;
            }
            return 0;
        }

        public static get instance(): DelegateConfig
        {
            if (DelegateConfig._instance == null) 
            {
                DelegateConfig._instance = new DelegateConfig();
            }
            return DelegateConfig._instance;
        }

        /* internal */ /* var */_taskDelegateMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_copyDelegateMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: DelegateConfig;
    }
